package com.example.demo.service.impl;

import com.example.demo.mapper.StudentMapper;
import com.example.demo.service.PropagationService;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by liujiahao on 2019/5/9.
 */
@Service
public class PropagationServiceImpl implements PropagationService{
    @Autowired
    private StudentMapper mapper;
    @Transactional
    @Override
    public void fun1() {
        fun2();
        //throw  new RuntimeException("dsdasd");
    }

    @Override
    @Transactional(propagation=Propagation.REQUIRES_NEW)
    public void fun2() {
       /* PropagationService propagationService = (PropagationService) AopContext.currentProxy();
        propagationService.fun3();*/
        mapper.update();
        try {
            fun3();
        } catch (Exception e) {
            e.printStackTrace();
        }
        /*for (int i = 0; i < 5; i++) {
            propagationService.fun3();
        }*/
        //throw  new RuntimeException("dsdasd");
    }

    @Override
    @Transactional(propagation=Propagation.REQUIRES_NEW)
    public void fun3(){
        mapper.update();
        throw new RuntimeException("sss");
    }
}
